//
//  UIBarButtonItem+Externsion.swift
//  新浪微博
//
//  Created by fanhoucheng on 16/9/22.
//  Copyright © 2016年 fanhoucheng. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    //参数:1.文字,2.图片,3.target,4.响应方法
    convenience init(title:String = "", imageName:String = "", target:Any?, action:Selector) {
        let btn = UIButton()
        
        //文字
        btn.setTitle(title, for: .normal)
        
        //文字颜色
        btn.setTitleColor(UIColor.darkGray, for: .normal)
        btn.setTitleColor(UIColor.orange, for: .highlighted)
        
        //设置字号
        btn.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        
        //图片
        if imageName != "" {
            
            btn.setImage(UIImage(named:imageName), for: UIControlState.normal)
            btn.setImage(UIImage(named:imageName + "_highlighted"), for: .highlighted)
        }
        btn.sizeToFit()
        btn.addTarget(target, action: action, for: .touchUpInside)
        
        self.init()
        
        self.customView = btn
        
        //添加响应
    }
    
}
